﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using NLBS.Data;
using System.Collections.Generic;
using NLBS.Web;
namespace NLBS.Blog.View.Default.UserControls
{
    public static class a
    {
       
    }
    public partial class ArticleListConent : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
         
        }

        public List<blog_Article> ArtList
        {
            get
            {
                BlogDataContext database = new BlogDataContext();
                IQueryable<blog_Article> query = database.blog_Articles.AsQueryable<blog_Article>();
                if (this.GetBlogIDQuery().HasValue)
                    query.Where(e => e.PathID == this.GetBlogIDQuery().Value);
                if(CatIdQuery.HasValue)
                    query=query.Where(e=>e.CatID==CatIdQuery.Value);
                if (!string.IsNullOrEmpty(this.GetBlogNameQuery()))
                    query = query.Where(e => e.PathID == database.aspnet_Paths.Where(p => p.Path.ToLower() == this.GetBlogNameQuery().ToLower()).FirstOrDefault<aspnet_Path>().PathId);
                if (!string.IsNullOrEmpty(CatReWriteUrlQuery))
                    query = query.Where(e => e.blog_Category.ReWriteUrl.ToLower() == CatReWriteUrlQuery.ToLower());
                if (UserIdQuery.HasValue)
                    query = query.Where(e => e.AuthorID == UserIdQuery.Value);

                return query
                    .Skip(StartIndex * PageSize)
                    .Take(PageSize).ToList<blog_Article>();
            }
        }

        public Guid? UserIdQuery
        {
            get
            {
                return Request.GetQueryGuid("userId");
            }
        }

        public Guid? CatIdQuery
        {
            get
            {
                return Request.GetQueryGuid("cat");
            }
        }

        public string CatReWriteUrlQuery
        {
            get
            {
                return Request.QueryString["catName"];
            }
        }

        public string TagQuery
        {
            get
            {
                return Request.QueryString["tag"];
            }
        }

        public int StartIndex
        {
            get
            {
                int page = Request.GetQueryInt("page");
                return page>0 ? page : 0;
            }
        }

        public int PageSize
        {
            get
            {
                return blog_Setting.Instance().ArticlePerPageNormal;
            }
        }
    }
}